package com.hanthink.web.controller.system;

import java.util.List;

import com.hanthink.common.core.domain.model.LoginUser;
import com.hanthink.common.utils.ServletUtils;
import com.hanthink.framework.web.service.TokenService;
import com.hanthink.system.domain.manhour.ProductionPlanAssistInShift;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.EmRoaster;
import com.hanthink.system.service.IEmRoasterService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * -Controller
 * 
 * @author hanthink
 * @date 2022-04-14
 */
@RestController
@RequestMapping("/system/Roaster")
public class EmRoasterController extends BaseController
{
    @Autowired
    private IEmRoasterService emRoasterService;

    @Autowired
    private TokenService tokenService;
    /**
     * 查询-列表
     */
    @PreAuthorize("@ss.hasPermi('system:Roaster:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmRoaster emRoaster)
    {
        startPage();
        List<EmRoaster> list = emRoasterService.selectEmRoasterList(emRoaster);
        return getDataTable(list);
    }
    @GetMapping("/importTemplate") // 下载导入模板 fmc
    public AjaxResult importTemplate() {
        ExcelUtil<EmRoaster> util = new ExcelUtil<EmRoaster>(EmRoaster.class);
        return util.importTemplateExcel("生产排班表");
    }
    @Log(title = "生产排班表", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('system:Roaster:import')")
    @PostMapping("/import")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<EmRoaster> util = new ExcelUtil<EmRoaster>(EmRoaster.class);
        List<EmRoaster> itemList = util.importExcel(file.getInputStream());
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        String operName = loginUser.getUsername();
        String message = emRoasterService.importEmRoasteritem(itemList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    /**
     * 导出-列表
     */
    @PreAuthorize("@ss.hasPermi('system:Roaster:export')")
    @Log(title = "-", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EmRoaster emRoaster)
    {
        List<EmRoaster> list = emRoasterService.selectEmRoasterList(emRoaster);
        ExcelUtil<EmRoaster> util = new ExcelUtil<EmRoaster>(EmRoaster.class);
        return util.exportExcel(list, "Roaster");
    }

    /**
     * 获取-详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:Roaster:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(emRoasterService.selectEmRoasterById(id));
    }

    /**
     * 新增-
     */
    @PreAuthorize("@ss.hasPermi('system:Roaster:add')")
    @Log(title = "-", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmRoaster emRoaster)
    {
        return toAjax(emRoasterService.insertEmRoaster(emRoaster));
    }

    /**
     * 修改-
     */
    @PreAuthorize("@ss.hasPermi('system:Roaster:edit')")
    @Log(title = "-", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmRoaster emRoaster)
    {
        return toAjax(emRoasterService.updateEmRoaster(emRoaster));
    }

    /**
     * 删除-
     */
    @PreAuthorize("@ss.hasPermi('system:Roaster:remove')")
    @Log(title = "-", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(emRoasterService.deleteEmRoasterByIds(ids));
    }
}
